<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form
                :model="queryParams"
                class="mb-[-16px]"
                inline
            >
                <el-form-item label="订单号" prop="sn">
                    <el-input v-model="queryParams.sn" class="w-[280px]" clearable placeholder="请输入" />
                </el-form-item>
                <el-form-item label="提现金额" prop="money">
                    <el-input v-model="queryParams.money" class="w-[280px]" clearable placeholder="请输入提现金额" />
                </el-form-item>
                <el-form-item class="w-[280px]" label="提现状态" prop="status">
                    <el-select v-model="queryParams.status" clearable placeholder="请选择提现状态">
                        <el-option label="已发起" value="1" />
                        <el-option label="成功" value="2" />
                        <el-option label="失败" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card v-loading="pager.loading" class="!border-none" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists">
                    <el-table-column label="订单号" prop="sn" show-overflow-tooltip width="200" />
                    <el-table-column label="账号类型" prop="account_type" show-overflow-tooltip>
                        <template #default="{ row }">
                            {{ row.account_type == 'agent' ? '代理商' : row.account_type == 'dealer' ? '经销商' : '分账人'
                            }}
                        </template>
                    </el-table-column>
                    <el-table-column label="提现金额" prop="money" show-overflow-tooltip />
                    <el-table-column label="提现状态" prop="status" show-overflow-tooltip>
                        <template #default="{ row }">
                            <el-tag v-if="row.status == 1" type="info">已发起</el-tag>
                            <el-tag v-if="row.status == 2" type="success">成功</el-tag>
                            <el-tag v-if="row.status == 3" type="danger">失败</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="发起时间" prop="req_time" show-overflow-tooltip width="150" />
                    <el-table-column label="到账时间" prop="into_time" show-overflow-tooltip width="150" />
                    <el-table-column label="失败原因" prop="fail_response" show-overflow-tooltip />
                    <el-table-column fixed="right" label="操作" width="120">
                        <template #default="{ row }">
                            <el-button
                                v-perms="['boom.boom_withdraw/edit']"
                                link
                                type="primary"
                                @click="handleEdit(row)"
                            >
                                详情
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @close="showEdit = false" @success="getLists" />
    </div>
</template>

<script lang="ts" name="boomWithdrawLists" setup>
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiBoomWithdrawLists } from '@/api/boom_withdraw'
import EditPopup from './edit.vue'

const editRef = shallowRef<InstanceType<typeof EditPopup>>()
// 是否显示编辑框
const showEdit = ref(false)


// 查询条件
const queryParams = reactive({
    sn: '',
    account_type: '',
    account_id: '',
    money: '',
    status: '',
    req_time: '',
    into_time: '',
    fail_response: '',
    transfer_bill_no: ''
})


// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiBoomWithdrawLists,
    params: queryParams
})


// 编辑
const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
    editRef.value?.setFormData(data)
}

getLists()
</script>

